<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-news-edit" th:object="${comment}">
			<input name="commentId"  type="hidden"  th:field="*{commentId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label">内容：</label>
				<div class="col-sm-8">
					<input class="form-control"  name="content" th:field="*{content}" id="content" type="hidden">
					<div class="summernote"></div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="${comment.status == '0' ? true : false}"  class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>

			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
	<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
	<script>
        $("#form-news-edit").validate({
            rules:{
                title:{
                    required:true,
                },
                content:{
                    required:true,
                },

            },
            messages: {
            },
            submitHandler:function(form){
                edit();
            }
        });

        function edit() {
        	var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
        	var commentId = $('#commentId').val();
        	var content = $('.summernote').code();;
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "system/comment/edit",
        		data : {
        		    status:status,
					commentId:commentId,
					content:content
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }

        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
        	var deptId = $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择部门',
				width: "380",
				height: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
    			var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}

		$(function () {
            $('.summernote').summernote({
                height : '220px',
                lang : 'zh-CN'
            });
            var content = $("#content").val();
            $('.summernote').code(content);
        });

    </script>
</body>
</html>
